<?php

namespace App\Utils;

use Illuminate\Support\Facades\Redis;

class RedisUtil
{
    public static function set($key, $value, $expire=null)
    {
        Redis::set($key, $value);
        if($expire) {
            Redis::expire($key, $expire);
        }
    }

    public static function get($key)
    {
        return Redis::get($key);
    }

    public static function del($key)
    {
        return Redis::del($key);
    }

    public static function lpush($key, $value)
    {
        return Redis::lpush($key, $value);
    }

    public static function rpop($key)
    {
        return Redis::rpop($key);
    }

    public static function incrby($key, $value, $expire = null)
    {
        Redis::INCRBY($key, $value);
        if ($expire){
            Redis::expire($key, $expire);
        }
    }

    public static function hMset($key, $value, $expire=0)
    {
        Redis::hMset($key, $value);
        if ($expire) {
            Redis::expire($key, $expire);
        }
    }

    public static function hGetAll($key)
    {
        return Redis::hGetAll($key);
    }

    public static function sadd($key, $value, $expire=0)
    {
        Redis::SADD($key, $value);
        if ($expire){
            Redis::expire($key, $expire);
        }
    }

    public static function smembers($key)
    {
        return Redis::SMEMBERS($key);
    }

    public static function srem($key, $member)
    {
        return Redis::SREM($key, $member);
    }

    public static function __callStatic($method, $arguments)
    {
        return call_user_func_array([Redis::class, $method], $arguments);
    }
}
